package com.qcby.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qcby.admin.dao.SysRoleMapper;
import com.qcby.admin.model.SysRole;
import com.qcby.admin.model.SysUserRole;
import com.qcby.admin.dao.SysUserRoleMapper;
import com.qcby.admin.service.SysUserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qcby.framwork.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户和角色关联表 服务实现类
 * </p>
 *
 * @author admin
 * @since 2024-09-20
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements SysUserRoleService {
    @Autowired
    private SysRoleMapper roleMapper;
    @Autowired
    private SysUserRoleMapper userRoleMapper;

    @Override
    public List<SysRole> listUserRole(Long userId) {
        return roleMapper.listUserRole(userId);
    }

    @Override
    public List<Long> selectRoleIds(Long userId) {
        return roleMapper.selectRoleIds(userId);
    }

    @Override
    public ResponseResult removeByRoleId(Long id) {
        QueryWrapper<SysUserRole> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id",id);

        int deleteById = userRoleMapper.delete(queryWrapper);
        if(deleteById>0) return ResponseResult.okResult();
        return ResponseResult.errorResult(500,"没有找到与用户关联的角色");
    }
}
